/*
 * @Author: hutong huareu980@163.com
 * @Date: 2023-06-13 12:20:18
 * @LastEditors: hutong huareu980@163.com
 * @LastEditTime: 2023-06-15 14:02:01
 * @FilePath: /smart-web-app/composables/useContentInfo.ts
 * @Description:
 */
export const useContentInfo = (list: any) => {
  const item = list?.[0] ?? {};
  const { locale } = useI18n();
  const info = computed(() => {
    return {
      ...setItem(item),
      children:
        item.children && item.children.length ? reSetInfo(item.children) : [],
    };
  });

  const setItem = (info: any) => {
    if (!info) return {};
    return {
      id: info.id,
      pid: info.pid,
      images:
        info.images && info.images.length
          ? info.images.split(";").map((url: string) => oss_url + "/" + url)
          : [],
      title: info[locale.value + "_t"],
      content: info[locale.value + "_content"],
    };
  };

  const reSetInfo = (arr: any) => {
    return arr.map((info: any) => {
      return {
        ...setItem(info),
        children:
          info.children && info.children.length ? reSetInfo(info.children) : [],
      };
    });
  };
  return {
    info,
  };
};
